﻿using System;
using System.Runtime.Serialization;

namespace Persons
{
    [Serializable]
    public class Person : ISerializable
    {
        public Person(int id, string firstName, string lastName, int age, string mobilePhone, Gender pGender)
        {
            Id = id;
            FirstName = firstName;
            LastName = lastName;
            Age = age;
            MobilePhone = mobilePhone;
            PGender = pGender;
        }

        public Person()
        {
            Id = -1;
            FirstName = "";
            LastName = "";
            Age = -1;
            MobilePhone = "";
            PGender = Gender.Unknown;
        }

        protected Person(SerializationInfo info, StreamingContext context)
        {
            Id = info.GetInt32("Id");
            FirstName = info.GetString("FirstName");
            LastName = info.GetString("LastName");
            Age = info.GetInt32("Age"); ;
            MobilePhone = info.GetString("MobilePhone");
            PGender = (Gender)info.GetValue("PGender", typeof(Gender));
        }

        public Gender PGender { get; set; }

        public string MobilePhone { get; set; }

        public int Age { get; set; }

        public string LastName { get; set; }

        public string FirstName { get; set; }

        public int Id { get; set; }

        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Id", Id);
            info.AddValue("FirstName", FirstName);
            info.AddValue("LastName", LastName);
            info.AddValue("Age", Age);
            info.AddValue("MobilePhone", MobilePhone);
            info.AddValue("PGender", PGender);
        }
    }
}
